﻿using System.Diagnostics;
using System.Windows;
using System.Windows.Media;

namespace JumpingBalls
{
    public partial class Block
    {
        private readonly object brushLocker = new object();

        private bool isBallStoryBoardOn;

        public int Row { get; private set; }

        public int Col { get; private set; }

        public const int BlockLength = 52;

        public Block(int row, int col)
        {
            InitializeComponent();

            this.Row = row;

            this.Col = col;
        }

        public void StartBallStoryBoard()
        {
            isBallStoryBoardOn = true;
            BallStoryBoard.Begin();
        }

        public void StopBallStoryBoard()
        {
            isBallStoryBoardOn = false;
            BallStoryBoard.Stop();
        }

        public void ChangeBallStoryBoard()
        {
            if (isBallStoryBoardOn)
            {
                StopBallStoryBoard();
            }
            else
            {
                StartBallStoryBoard();
            }
        }

        public void ChangeBallBrush(int value, bool isEraseBall)
        {
            lock (brushLocker)
            {
                Debug.WriteLine(string.Format("[{0},{1}] SET brushValue = {2}", Row, Col, value));

                GradientBrush brush = Application.Current.Resources[string.Format("BallBrush{0}", value)] as GradientBrush;

                ball.Fill = brush;
            }

            Debug.WriteLine(string.Empty);
        }
    }
}
